package com.own.component.common.login.user;

import com.own.component.common.login.function.MenuOperationFunction;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Collection;

/**
 * DefaultPermissionUser
 *
 * @author chenxueli
 * @date 2023-08-10 16:30:39
 */
public final class DefaultPermissionUser extends DefaultLoginUser implements BasePermissionUser {

    public static final BasePermissionUser DEFAULT = new DefaultPermissionUser();

    @Setter
    private Collection<String> roleNameList;

    private MenuOperationFunction function;

    public DefaultPermissionUser() {
        super();
        this.roleNameList = new ArrayList<>();
    }

    public DefaultPermissionUser(BaseLoginUser loginUser, Collection<String> roleNameList) {
        super(loginUser);
        this.roleNameList = roleNameList;
    }

    public DefaultPermissionUser(BaseLoginUser loginUser, Collection<String> roleNameList, MenuOperationFunction function) {
        super(loginUser);
        this.roleNameList = roleNameList;
        this.function = function;
    }

    /**
     * 角色名称列表
     *
     * @return 角色名称列表
     */
    @Override
    public Collection<String> roleNameList() {
        return roleNameList;
    }

    /**
     * 验证权限是否可用
     *
     * @param module    模块名称
     * @param operation 操作名称
     * @return 是否可用
     */
    @Override
    public boolean checkOperation(String module, String operation) {
        return function.run(module, operation);
    }

}
